#include <assert.h>
#include <iostream>
#include <vector>

using namespace std;


class doubleList{
private:
	vector<double>*dList;
public:
	doubleList();
	~doubleList();

	bool insertTo(int pos, double num);
	bool remove_ifNumInPos(int pos, double num);

	// temporal function
	void print(){
		if (dList->size() == 0) {
			cout<<"Empty"<<endl;
			return;
		}
		for (int i = 0; i < dList->size(); i++){
			cout<<(*dList)[i]<<"|";
		}

		cout<<endl;
	}
};


// Antonopoulos Spyridon
// bool insertTo(int pos, double num) 
// Eisagei ton arithmo num sti thesi pos tis listas
// pos :: [0,1..]
// Prepei to pos na einai thetiko i 0 kai mikrotero i iso me to megethos tis listas
// e.g insertTo(0,3.3);

bool doubleList::insertTo(int pos,double num){

	if ( pos < 0 ) {
		cerr<<"Cannot insert element "<<num<<" in position "<<pos<<" ,Negative Position Given "<<endl; 
		return false;
	}

	if ( pos > this->dList->size()) {
		cerr<<"Cannot insert element "<<num<<" in position "<<pos<<" ,Out of List Bounds"<<endl; 
		return false;
	}

	vector<double>::iterator it1 = this->dList->begin();
	// moving the iterator to position [pos]
	for (int i = 0; i < pos; i++) 
		it1++;

	int oldL = this->dList->size();
	this->dList->insert(it1,num);
	assert(this->dList->size() == oldL+1);
	return true;

}

// Antonopoulos Spyridon
// bool remove_ifNumInPos(int pos, double num) 
// Psaxnei an sti thesi 'pos' tis listas yparxei o arithmos 'num'
// An to brei tote ton diagrafei apo ti lista kai metakinei ta upoloipa stoixeia
// pos :: [0,1..]
// e.g remove_ifNumInPos(0,3.3)
// returns true if element 3.3 is found in pos 0 and deleted
// return false if an error happened or element not found
// Prepei to pos na einai >= 0 kai < apo to size tis listas

bool doubleList::remove_ifNumInPos(int pos, double num) {
	
	if ( pos < 0 ) {
		cerr<<"Cannot find element "<<num<<" in position "<<pos<<" ,Negative Position Given "<<endl; 
		return false;
	}

	if ( pos >= this->dList->size()) {
		cerr<<"Cannot find element "<<num<<" in position "<<pos<<" ,Out of List Bounds"<<endl; 
		return false;
	}
	
	vector<double>::iterator it1 = this->dList->begin();
	// moving the iterator to position [pos]
	for (int i = 0; i < pos; i++) 
		it1++;

	if ((*it1) == num) {
		int oldS = this->dList->size();
		this->dList->erase(it1);
		assert(this->dList->size() == oldS-1);
		return true;
	}
	else
		return false;

}

doubleList::doubleList(){
	this->dList = new vector<double>();
}

doubleList::~doubleList(){
	delete this->dList;
}




int main() {

	doubleList d1;

	cout<<"1.";d1.print();
	if (!d1.insertTo(1,0.33)) cout<<"Cannot insert element 0.33 in position 1 (OK)"<<endl;
	else					  cout<<"Inserted element 0.33 in position 1 (FAIL)"<<endl;

	cout<<"2.";d1.print();
	if (!d1.insertTo(0,0.33)) cout<<"Cannot insert element 0.33 in position 0 (FAIL)"<<endl;
	else					  cout<<"Inserted element 0.33 in position 0 (OK)"<<endl;
	
	cout<<"3.";d1.print();
	if (!d1.insertTo(1,0)) cout<<"Cannot insert element 0 in position 1 (FAIL)"<<endl;
	else					  cout<<"Inserted element 0 in position 1 (OK)"<<endl;

	cout<<"4.";d1.print();
	if (!d1.insertTo(0,-3.2)) cout<<"Cannot insert element -3.2 in position 0 (FAIL)"<<endl;
	else					  cout<<"Inserted element -3.2 in position 0 (OK)"<<endl;

	cout<<"5.";d1.print();
	if (!d1.insertTo(0,0.33)) cout<<"Cannot insert element 0.33 in position 1 (FAIL)"<<endl;
	else					  cout<<"Inserted element 0.33 in position 1 (OK)"<<endl;

	cout<<"6.";d1.print();
	if (!d1.insertTo(10,0.33)) cout<<"Cannot insert element 0.33 in position 10 (OK)"<<endl;
	else					  cout<<"Inserted element 0.33 in position 10 (FAIL)"<<endl;

	cout<<"7.";d1.print();
	if (d1.remove_ifNumInPos(0,0.33))		cout<<"Num 0.33 found in position 0 and deleted (OK)"<<endl;
	else cout<<"Num 0.33 not found in position 0"<<endl;
	
	cout<<"8.";d1.print();
	if (d1.remove_ifNumInPos(0,0.33))		cout<<"Num 0.33 found in position 0 and deleted (FAIL)"<<endl;
	else cout<<"Num 0.33 not found in position 0(OK)"<<endl;

	cout<<"9.";d1.print();
	if (d1.remove_ifNumInPos(10,0.33))		cout<<"Num 0.33 found in position 10 and deleted (FAIL)"<<endl;
	else cout<<"Num 0.33 not found in position 10(OK)"<<endl;

	cout<<"10.";d1.print();
	if (d1.remove_ifNumInPos(1,0.33))		cout<<"Num 0.33 found in position 1 and deleted (ok)"<<endl;
	else cout<<"Num 0.33 not found in position 1(FAIL)"<<endl;
	
	cout<<"11.";d1.print();
	if (d1.remove_ifNumInPos(1,0))		cout<<"Num 0 found in position 1 and deleted (ok)"<<endl;
	else cout<<"Num 0 not found in position 1(FAIL)"<<endl;

	cout<<"12.";d1.print();
	if (d1.remove_ifNumInPos(0,-3.2))		cout<<"Num -3.2 found in position 0 and deleted (ok)"<<endl;
	else cout<<"Num -3.2 not found in position 0(FAIL)"<<endl;

	cout<<"13.";d1.print();
	if (d1.remove_ifNumInPos(0,-3.2))		cout<<"Num -3.2 found in position 0 and deleted (FAIL)"<<endl;
	else cout<<"Num -3.2 not found in position 0(OK)"<<endl;
	
	cout<<"14.";d1.print();
	if (d1.remove_ifNumInPos(-10,-3.2))		cout<<"Num -3.2 found in position -10 and deleted (FAIL)"<<endl;
	else cout<<"Num -3.2 not found in position -10(OK)"<<endl;

	cout<<"15.";d1.print();
	if (!d1.insertTo(0,0.33)) cout<<"Cannot insert element 0.33 in position 0 (FAIL)"<<endl;
	else					  cout<<"Inserted element 0.33 in position 0 (OK)"<<endl;

	cout<<"16.";d1.print();
	if (!d1.insertTo(1,2.2)) cout<<"Cannot insert element 2.2 in position 1 (FAIL)"<<endl;
	else					  cout<<"Inserted element 2.2 in position 1 (OK)"<<endl;
	cout<<"Final.";d1.print();

	system("Pause");
}